package com.scheduling.machine.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.scheduling.machine.entity.MachineTypeMaterialCompatibility;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 机器类型原料兼容性 Mapper接口
 *
 * @author 开发团队
 * @since 2025-05-29
 */
@Mapper
public interface MachineTypeMaterialCompatibilityMapper extends BaseMapper<MachineTypeMaterialCompatibility> {

    /**
     * 查询机器类型与原料的兼容性
     */
    @Select("SELECT * FROM machine_type_material_compatibility " +
            "WHERE machine_type_id = #{machineTypeId} AND material_id = #{materialId}")
    MachineTypeMaterialCompatibility selectByMachineTypeAndMaterial(@Param("machineTypeId") String machineTypeId,
                                                                    @Param("materialId") String materialId);

    /**
     * 查询机器类型的所有兼容原料
     */
    @Select("SELECT * FROM machine_type_material_compatibility " +
            "WHERE machine_type_id = #{machineTypeId} AND compatible = true")
    List<MachineTypeMaterialCompatibility> selectCompatibleMaterials(@Param("machineTypeId") String machineTypeId);

    /**
     * 查询机器类型的所有不兼容原料
     */
    @Select("SELECT * FROM machine_type_material_compatibility " +
            "WHERE machine_type_id = #{machineTypeId} AND compatible = false")
    List<MachineTypeMaterialCompatibility> selectIncompatibleMaterials(@Param("machineTypeId") String machineTypeId);

    /**
     * 检查机器类型与原料列表的兼容性
     */
    @Select("<script>" +
            "SELECT machine_type_id, material_id, compatible, reason " +
            "FROM machine_type_material_compatibility " +
            "WHERE machine_type_id = #{machineTypeId} " +
            "AND material_id IN " +
            "<foreach collection='materialIds' item='materialId' open='(' separator=',' close=')'>" +
            "#{materialId}" +
            "</foreach>" +
            "</script>")
    List<MachineTypeMaterialCompatibility> checkMaterialsCompatibility(@Param("machineTypeId") String machineTypeId,
                                                                       @Param("materialIds") List<String> materialIds);
} 